package org.shan.lis;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.HeadlessException;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;

/**
 * Created by amanda.shan on 2019-07-05.
 */
public class LisFrame extends JFrame {

    private String[][] data = {};
    private String[] dataTitle = {"患者编号", "样本ID", "通道", "结果", "时间"};
    private JTable jtable = new JTable(data, dataTitle);
    private JScrollPane jscrollpane = new JScrollPane(jtable);

    private JPanel contentPane;

    public LisFrame() throws HeadlessException {

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 800, 500);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(new BorderLayout());

        contentPane.add(jscrollpane, BorderLayout.CENTER);
    }

    public void refresh(String[][] data) {

        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {

                contentPane.remove(jscrollpane);

                jtable = new JTable(data, dataTitle);
                jscrollpane = new JScrollPane(jtable);

                contentPane.add(jscrollpane, BorderLayout.CENTER);

                contentPane.updateUI();
            }
        });

    }

}
